import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:getx/config/theme/app_theme.dart';
import 'package:getx/router/router_names.dart';
import 'package:getx/router/router_views.dart';
import 'package:getx/services/impl/storage_services_impl.dart';
import 'package:loader_overlay/loader_overlay.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  ///启动页设置
  await initServices();

  ///透明任务栏
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(statusBarColor: Colors.transparent));
  runApp(MyApp());
}

Future<void> initServices() async {
  ///初始化缓存后添加到Get里面
  await Get.putAsync<SharedPreferences>(() async => await StorageServicesImpl().init());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GlobalLoaderOverlay(
      child: GetMaterialApp(
        theme: ThemeData(
          brightness: Brightness.light,
          colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Colors.blue),
          primarySwatch: Colors.blue,
          scaffoldBackgroundColor: Colors.transparent,
          appBarTheme: const AppBarTheme(
            backgroundColor: Colors.white24,
            foregroundColor: Colors.black,
            elevation: 0,
            titleTextStyle: TextStyle(color: Colors.black, fontSize: 18),
            toolbarHeight: 48,
          ),
          inputDecorationTheme: const InputDecorationTheme(
            border: OutlineInputBorder(),
            hintStyle: TextStyle(color: Colors.black54, fontSize: 14),
          ),
          elevatedButtonTheme: ElevatedButtonThemeData(
            style: ElevatedButton.styleFrom(
              elevation: 0,
              backgroundColor: Colors.white38,
              foregroundColor: Colors.blue,
              minimumSize: Size(double.infinity, 48),
              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
              textStyle: TextStyle(fontSize: 18, wordSpacing: 2, letterSpacing: 2),
            ),
          ),
        ),
        darkTheme: AppTheme.dark,
        initialRoute: RouterNames.splash,
        getPages: RouterViews.getAllViews(),
      ),
    );
  }
}
